package org.linlinjava.litemall.wx.util;

import org.linlinjava.litemall.wx.vo.PurchaseStatisticsVo;

public class WxPurchaseStatusUtil {
	// litemall_form_purchase
	public static final byte FP_STATUS_0 = 0;
	public static final byte FP_STATUS_1 = 1;
	public static final byte FP_STATUS_2 = 2;
	public static final byte FP_STATUS_3 = 3;
	public static final byte FP_STATUS_4 = 4;
	public static final byte FP_STATUS_5 = 5;
	// litemall_form_purchase_item
	public static final byte FPI_STATUS_0 = 0;
	public static final byte FPI_STATUS_1 = 1;
	public static final byte FPI_STATUS_2 = 2;
	public static final byte FPI_STATUS_3 = 3;
	// litemall_form_purchase_item
	public static final byte FPI_CHECK_STATUS_0 = 0;
	public static final byte FPI_CHECK_STATUS_1 = 1;
	public static final byte FPI_CHECK_STATUS_2 = 2;
	public static final byte FPI_CHECK_STATUS_3 = 3;
	// litemall_quote_price
	public static final byte QP_STATUS_0 = 0;
	public static final byte QP_STATUS_1 = 1;

	/**
	 * 待报价
	 * 
	 * @param vo
	 * @return
	 */
	public static boolean isWaitQuteStatus(PurchaseStatisticsVo vo) {
		if (vo != null && checkEqual(vo.getCheckStatus(), FPI_CHECK_STATUS_0)
				&& checkEqual(vo.getFpStatus(), FP_STATUS_2)
				&& (checkEqual(vo.getFpiStatus(), FPI_STATUS_0) || checkEqual(vo.getFpiStatus(), FPI_STATUS_1))
				&& isNull(vo.getQpStatus())) {
			return true;
		}
		return false;
	}

	/**
	 * 已报价
	 * 
	 * @param vo
	 * @return
	 */
	public static boolean isQuotedStatus(PurchaseStatisticsVo vo) {
		if (vo != null && checkEqual(vo.getCheckStatus(), FPI_CHECK_STATUS_0)
				&& checkEqual(vo.getFpStatus(), FP_STATUS_2)
				&& (checkEqual(vo.getFpiStatus(), FPI_STATUS_0) || checkEqual(vo.getFpiStatus(), FPI_STATUS_1))
				&& checkEqual(vo.getQpStatus(), QP_STATUS_0)) {
			return true;
		}
		return false;
	}

	/**
	 * 已中标
	 * 
	 * @param vo
	 * @return
	 */
	public static boolean isWinningBidStatus(PurchaseStatisticsVo vo) {
		if (vo != null
				&& (checkEqual(vo.getCheckStatus(), FPI_CHECK_STATUS_0) || checkEqual(vo.getCheckStatus(), FPI_CHECK_STATUS_1))
				&& checkEqual(vo.getFpStatus(), FP_STATUS_2)
				&& (checkEqual(vo.getFpiStatus(), FPI_STATUS_2) || checkEqual(vo.getFpiStatus(), FPI_STATUS_3))
				&& checkEqual(vo.getQpStatus(), QP_STATUS_1)) {
			return true;
		}
		return false;
	}

	/**
	 * 未中标
	 * 
	 * @param vo
	 * @return
	 */
	public static boolean isNotBidStatus(PurchaseStatisticsVo vo) {
		if (vo != null && checkEqual(vo.getFpStatus(), FP_STATUS_2)
				&& (checkEqual(vo.getFpiStatus(), FPI_STATUS_2) || checkEqual(vo.getFpiStatus(), FPI_STATUS_3))
				&& checkEqual(vo.getQpStatus(), QP_STATUS_0)) {
			return true;
		}
		return false;
	}

	/**
	 * 送检中
	 * 
	 * @param vo
	 * @return
	 */
	public static boolean isWaitCheckStatus(PurchaseStatisticsVo vo) {
		if (vo != null && (checkEqual(vo.getFpStatus(), FP_STATUS_2) || checkEqual(vo.getFpStatus(), FP_STATUS_4) || checkEqual(vo.getFpStatus(), FP_STATUS_5))
				&& (checkEqual(vo.getFpiStatus(), FPI_STATUS_2))
				&& (checkEqual(vo.getCheckStatus(), FPI_CHECK_STATUS_1))
				&& checkEqual(vo.getQpStatus(), QP_STATUS_1)) {
			return true;
		}
		return false;
	}

	/**
	 * 检查合格
	 * 
	 * @param vo
	 * @return
	 */
	public static boolean isCheckOkStatus(PurchaseStatisticsVo vo) {
		if (vo != null && (checkEqual(vo.getFpStatus(), FP_STATUS_2) || checkEqual(vo.getFpStatus(), FP_STATUS_4) || checkEqual(vo.getFpStatus(), FP_STATUS_5))
				&& (checkEqual(vo.getFpiStatus(), FPI_STATUS_3))
				&& (checkEqual(vo.getCheckStatus(), FPI_CHECK_STATUS_2))
				&& checkEqual(vo.getQpStatus(), QP_STATUS_1)) {
			return true;
		}
		return false;
	}

	/**
	 * 检查不合格
	 * 
	 * @param vo
	 * @return
	 */
	public static boolean isCheckFailStatus(PurchaseStatisticsVo vo) {
		if (vo != null && (checkEqual(vo.getFpStatus(), FP_STATUS_2) || checkEqual(vo.getFpStatus(), FP_STATUS_4) || checkEqual(vo.getFpStatus(), FP_STATUS_5))
				&& (checkEqual(vo.getFpiStatus(), FPI_STATUS_3))
				&& (checkEqual(vo.getCheckStatus(), FPI_CHECK_STATUS_3))
				&& checkEqual(vo.getQpStatus(), QP_STATUS_1)) {
			return true;
		}
		return false;
	}

	public static boolean checkEqual(Byte v1, Byte v2) {
		if (v1 == null || v2 == null) {
			return false;
		}
		return v1.byteValue() == v2.byteValue();
	}

	public static boolean isNull(Byte v1) {
		return v1 == null;
	}
}
